package rsstutorials;

import edu.app.dao.IDAO;
import edu.app.dao.RecetteDAO;
import edu.app.gui.Menu;
import edu.app.persistence.Recette;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

public class Rsstutos extends javax.swing.JFrame {
byte[] person_image = null;
    String url;
 private IDAO<Recette> recetteDAO= new RecetteDAO();
    /**
     * Creates new form EventsRSSFrame
     */

    public String clearstr(String s)
    {
        int i =0;
     String s2="";
     while (i<s.length())
     {
         if (s.charAt(i)!='<')
         {
             s2=s2+s.charAt(i);
         }
         else
         {
             while (s.charAt(i)!='>')
             {
                 i++;
             }

         }
 i++;
     }
     return s2;
    }

    public Rsstutos(String url) {
        this.url = url;
        initComponents();
        setResizable(false);
        setBounds(50, 50,793, 600);
        getContentPane().setLayout(null);
       Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension windowSize = this.getSize();
        int windowX = Math.max(0, (screenSize.width  - windowSize.width ) / 2);
        int windowY = Math.max(0, (screenSize.height - windowSize.height) / 2)-20;
        this.setLocation(windowX, windowY);
         TableCellRenderer rendererFromHeader = jTable1.getTableHeader().getDefaultRenderer();
        JLabel headerLabel = (JLabel) rendererFromHeader;
        headerLabel.setHorizontalAlignment(JLabel.CENTER);
        DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer();
        dtcr.setHorizontalAlignment(SwingConstants.CENTER);
         jTable1.getColumnModel().getColumn(1).setMinWidth(0);
         jTable1.getColumnModel().getColumn(1).setMaxWidth(0);
       // jTable1.getColumn("Lien").setCellRenderer(dtcr);
        jTable1.getColumn("Tutorials").setCellRenderer(dtcr);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        getContentPane().setLayout(null);

        jTable1.setFont(new java.awt.Font("Gabriola", 0, 24));
        jTable1.setModel(new EventTableModel(url)
        );
        jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        jTable1.setRowHeight(45);
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable1);

        getContentPane().add(jScrollPane2);
        jScrollPane2.setBounds(20, 120, 470, 430);

        jLabel1.setFont(new java.awt.Font("Gabriola", 3, 36));
        jLabel1.setForeground(new java.awt.Color(0, 102, 255));
        jLabel1.setText("Pas a pas dans la cuisine");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(270, 0, 550, 62);

        jLabel7.setFont(new java.awt.Font("Gabriola", 0, 18));
        jLabel7.setText("Precedent");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(50, 80, 80, 31);

        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/app/gui/images/ret7.gif"))); // NOI18N
        jLabel16.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel16MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabel16MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabel16MouseExited(evt);
            }
        });
        getContentPane().add(jLabel16);
        jLabel16.setBounds(50, 30, 90, 50);
        getContentPane().add(jSeparator1);
        jSeparator1.setBounds(250, 50, 360, 30);

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/app/gui/images/cons7.gif"))); // NOI18N
        jLabel10.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel10MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabel10MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabel10MouseExited(evt);
            }
        });
        getContentPane().add(jLabel10);
        jLabel10.setBounds(610, 130, 70, 70);

        jLabel11.setFont(new java.awt.Font("Gabriola", 0, 24));
        jLabel11.setText("Acceder a la page de la recette");
        getContentPane().add(jLabel11);
        jLabel11.setBounds(540, 200, 270, 41);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/app/gui/images/vid2.jpg"))); // NOI18N
        getContentPane().add(jLabel2);
        jLabel2.setBounds(0, -110, 800, 790);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
      // jTextArea1.setText(clearstr(jTable1.getValueAt(jTable1.getSelectedRow(),1).toString()));
    }//GEN-LAST:event_jTable1MouseClicked

    private void jLabel10MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel10MouseEntered
                     jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/app/gui/images/cons72.gif")));

    }//GEN-LAST:event_jLabel10MouseEntered

    private void jLabel10MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel10MouseExited
                  jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/app/gui/images/cons7.gif")));

    }//GEN-LAST:event_jLabel10MouseExited

    private void jLabel10MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel10MouseClicked
        Desktop d=Desktop.getDesktop();
        try {
            try {
                // Browse a URL, say google.com
                d.browse(new URI(jTable1.getValueAt(jTable1.getSelectedRow(),1).toString()));
            } catch (URISyntaxException ex) {
                Logger.getLogger(Rsstutos.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (IOException ex) {
            Logger.getLogger(Rsstutos.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jLabel10MouseClicked

    private void jLabel16MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel16MouseClicked

        this.setVisible(false);
        
}//GEN-LAST:event_jLabel16MouseClicked

    private void jLabel16MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel16MouseEntered
        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/app/gui/images/ret72.gif")));
}//GEN-LAST:event_jLabel16MouseEntered

    private void jLabel16MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel16MouseExited
        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/app/gui/images/ret7.gif")));
}//GEN-LAST:event_jLabel16MouseExited

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel.
         */

        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Rsstutos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Rsstutos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Rsstutos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Rsstutos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Rsstutos("http://www.recettes-videos.com/rss.php").setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
